textview: Translate the cairo context instead of keeping y value
authorBenjamin Otte <otte@redhat.com>
Sun, 20 Feb 2011 22:29:49 +0000 (23:29 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 20 Feb 2011 22:43:42 +0000 (23:43 +0100)
This avoids overflow when transforming a large value to a pango unit.
To reproduce the problem:
seq 200000 > test.txt && tets/print-editor test.txt
Then scroll to around line 140.000 to see it (depends on font size of
course).

gtk/gtktextdisplay.c

index 383f52d1a908d6e897b4b837bda3528a6e46ec32..e217f8ad9cadde465ca79e5462b1036e75267710 100644 (file)
@@ -847,7 +847,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
                       cairo_t *cr,
                       GList **widgets)
 {
-  gint current_y;
+  gint offset_y;
   GSList *cursor_list;
   GtkTextRenderer *text_renderer;
   GtkTextIter selection_start, selection_end;
@@ -865,7 +865,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
   if (!gdk_cairo_get_clip_rectangle (cr, &clip))
     return;
 
-  line_list =  gtk_text_layout_get_lines (layout, clip.y, clip.y + clip.height, &current_y);
+  line_list = gtk_text_layout_get_lines (layout, clip.y, clip.y + clip.height, &offset_y);
 
   if (line_list == NULL)
     return; /* nothing on the screen */
@@ -873,6 +873,9 @@ gtk_text_layout_draw (GtkTextLayout *layout,
   text_renderer = get_text_renderer ();
   text_renderer_begin (text_renderer, widget, cr);
 
+  /* text_renderer_begin/end does cairo_save/restore */
+  cairo_translate (cr, 0, offset_y);
+
   gtk_text_layout_wrap_loop_start (layout);
 
   if (gtk_text_buffer_get_selection_bounds (layout->buffer,
@@ -926,7 +929,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
             }
 
           render_para (text_renderer, line_display,
-                       0, current_y,
+                       0, 0,
                        selection_start_index, selection_end_index);
 
           /* We paint the cursors last, because they overlap another chunk
@@ -962,7 +965,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
                }
  
              cursor_location.x = line_display->x_offset + cursor->x;
-             cursor_location.y = current_y + line_display->top_margin + cursor->y;
+             cursor_location.y = line_display->top_margin + cursor->y;
              cursor_location.width = 0;
              cursor_location.height = cursor->height;
 
@@ -974,7 +977,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
             }
         } /* line_display->height > 0 */
           
-      current_y += line_display->height;
+      cairo_translate (cr, 0, line_display->height);
       gtk_text_layout_free_line_display (layout, line_display);
       
       tmp_list = g_slist_next (tmp_list);